package controllers;
/**
 * User: bicho
 * Date: 23/07/12 21:58
 * Email: bichocj@gmail.com
 */

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.jamonapi.utils.Logger;
import models.Porcino;
import play.db.jpa.JPA;
import play.mvc.Controller;
import com.google.gson.JsonDeserializer;

import java.util.*;

public class Hembras extends Controller {

    public static void index() {

        List<Porcino> porcinos = Porcino.findAll();
        //List<User> users1 = User.findAll();
        renderJSON(porcinos);
    }

    public static void save(String a) {
        String body = params.data.get("body")[0];
        Gson gson = new GsonBuilder().setDateFormat("MM/dd/yyyy").create();

        Porcino porcino = gson.fromJson(body, Porcino.class);
        porcino = JPA.em().merge(porcino);
        porcino.sexo = "H";
        porcino.save();
        renderJSON(porcino);
    }

    public static void get(Long id) {
        //renderJSON(User.findById(id));
    }

    public static void delete(Long id) {
        //User user = User.findById(id);
        //user.delete();
        response.status = 204;
    }

}
